﻿// HSS.Forms.TriStateTreeView.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       TriStateTreeView.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace HSS.Forms
{
	#region TriStateTreeView
	/// <summary>
	/// A an extended CustomStateTreeView that holds state images for a <see cref="TriStateTreeNode"/>
	/// </summary>
	public class TriStateTreeView : CustomStateTreeView
	{
		#region Overrides
		/// <summary>
		/// Creaties a custom state image list for <see cref="TriStateTreeNode"/>s
		/// </summary>
		protected override void CreateStateImages()
		{
			base.CreateStateImages();

			System.Windows.Forms.VisualStyles.VisualStyleRenderer vsr = null;
			if (System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsSupported) vsr = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Button.CheckBox.UncheckedNormal);
			System.Drawing.Rectangle smallIconSize = new System.Drawing.Rectangle(0, 0, StateImageList.ImageSize.Width, StateImageList.ImageSize.Height);
			System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(StateImageList.ImageSize.Width, StateImageList.ImageSize.Height);

			using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
			{
				if (vsr == null)
				{
					System.Windows.Forms.ControlPaint.DrawMixedCheckBox(graphics, smallIconSize, System.Windows.Forms.ButtonState.Normal);
				}
				else
				{
					vsr.SetParameters(System.Windows.Forms.VisualStyles.VisualStyleElement.Button.CheckBox.UncheckedNormal);
					vsr.DrawBackground(graphics, smallIconSize);
				}
				StateImageList.Images.Add(bitmap, System.Drawing.Color.Transparent);

				if (vsr == null)
				{
					System.Windows.Forms.ControlPaint.DrawMixedCheckBox(graphics, smallIconSize, System.Windows.Forms.ButtonState.Checked);
				}
				else
				{
					vsr.SetParameters(System.Windows.Forms.VisualStyles.VisualStyleElement.Button.CheckBox.CheckedNormal);
					vsr.DrawBackground(graphics, smallIconSize);
				}
				StateImageList.Images.Add(bitmap, System.Drawing.Color.Transparent);

				if (vsr == null)
				{
					System.Windows.Forms.ControlPaint.DrawMixedCheckBox(graphics, smallIconSize, System.Windows.Forms.ButtonState.Pushed);
				}
				else
				{
					vsr.SetParameters(System.Windows.Forms.VisualStyles.VisualStyleElement.Button.CheckBox.MixedNormal);
					vsr.DrawBackground(graphics, smallIconSize);
				}
				StateImageList.Images.Add(bitmap, System.Drawing.Color.Transparent);
			}
		}
		#endregion
	}
	#endregion
}